import torch
import matplotlib.pyplot as plt


def tanh(x, w=1):
    a = torch.exp(w * x) - torch.exp(-w * x)
    b = torch.exp(w * x) + torch.exp(-w * x)
    return a / b


x = torch.linspace(0, 1, 40)
y1 = torch.cos(x * torch.pi) * x
y2 = y1 ** 2

plt.subplot(121)
plt.plot(x, y1, 'r-')
plt.subplot(122)
plt.plot(x, y2, 'r-')
plt.show()
